<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class AddStartYearToFeeAnnualOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('fee_annual_order', function (Blueprint $table) {
            $table->unsignedSmallInteger('startYear')->default(0)->comment('本期年费，开始年份')->after('endTime');
        });

        \App\Models\Fee\FeeAnnualOrderModel::query()->where('startYear', 0)->get()->map(function ($item) {
            $item->startYear = date('Y', $item->endTime);
            $item->save();

            dump($item->id);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('fee_annual_order', function (Blueprint $table) {
            $table->dropColumn('startYear');
        });
    }
}
